package com.cloudbroker.bcs.platform.ltb.middle.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by wangxu13798 on 2016/3/8.
 */
public class IOUtil {
    public static String inputStream2String(InputStream ips)
    {
        byte[] b = new byte[1024];
        int len = 0;
        StringBuffer sb = new StringBuffer();
        try
        {
            while ((len = ips.read(b)) != -1) {
                sb.append(new String(b, 0, len));
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return sb.toString();
    }
    public static Map inputStream2Map(InputStream ips){
        Map map = new HashMap();
        String str = inputStream2String(ips);
        JSONObject.parse(str);
        return map;
    }
    public static void main(String[] args){
        String param = IOUtil.inputStream2String(IOUtil.class.getClassLoader().getResourceAsStream("testdata.json"));
        System.out.println(param);
    }
}
